import {ref} from "vue";
import {getMenuList} from "@/api/system/menu";
import {searchForm} from "@/views/system/menu/hooks/useSearch";
import _ from "lodash"
import useBuildTreeSelectOptions from "@/hooks/useBuildTreeSelectOptions/useBuildTreeSeclectOptions";
export interface Menu {
    id:         number;
    name:       string;
    permission: null | string;
    path:       null | string;
    parentId:   number;
    icon:       string | null;
    component:  string|null;
    type:       number;
    sort:       number;
    dataStatus: number;
    isShowMenu: number | null;
    createTime: string;
    updateTime: string;
    children?:  Menu[];
}
const tableData = ref<Menu[]>([])
const tableLoading = ref<boolean>(false)
const {treeSelectOptions,buildTreeSelectOptions} =useBuildTreeSelectOptions()
function useTable() {
    function getDataList() {
        tableLoading.value = true
        getMenuList(searchForm).then(res=>{
            tableLoading.value = false
            tableData.value = res.data
            buildTreeSelectOptions(_.cloneDeep(res.data),"id",'name')
        })
    }
    return {
        treeSelectOptions,
        tableLoading,
        tableData,
        getDataList
    }
}
export default useTable
